package com.dongdongshop.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.Constant.DataResultConstant;
import com.dongdongshop.domain.DataResult;
import com.dongdongshop.em.DataResultEnum;
import com.dongdongshop.pojo.TbBrand;
import com.dongdongshop.service.BrandService;
import com.dongdongshop.service.TbGoogsService;
import com.dongdongshop.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("ToShow")
public class IndexController {

   // private Logger logger = LoggerFactory.getLogger(IndexController.class);

    @Reference
    private BrandService brandService;
    @Reference
    private UserService userService;
    @Reference
    private TbGoogsService tbGoogsService;

    @ResponseBody
    @RequestMapping("denglu")
    public DataResult denglu(String name,String pwd){
        Boolean b =userService.selectByName(name,pwd);
        return DataResult.buildDataResult(DataResultEnum.SUCCESS);
    }
    @RequestMapping("denglus")
    public String denglus(){
        return "login";
    }

    @RequestMapping("index")
    public String index(){
        //logger.debug("跳转查看页面");
        return "admin/index";
    }
    @RequestMapping("brandToshow")
    public String brandToshow(){

        return "admin/brandToshow";
    }

    @RequestMapping("selectAll")
    @ResponseBody
    public DataResult selectAll(){
        List<TbBrand> selevt = brandService.selevt();
        return DataResult.buildDataResult(DataResultEnum.SUCCESS).setData(selevt);
    }
    @RequestMapping("insert")
    @ResponseBody
    public DataResult insert(TbBrand tbBrand){
        Boolean b = brandService.insertinto(tbBrand);
        return new DataResult(100,"增加成功");
    }

    @RequestMapping("delete")
    @ResponseBody
    public DataResult delete(Long id){
        Boolean b =  brandService.deleteByid(id);
        return new DataResult(DataResultConstant.SUCCESS_CODE,DataResultConstant.SUCCESS_MESSAGE);
    }

    @RequestMapping("updata")
    @ResponseBody
    public DataResult updata(Long id){
        TbBrand updata = brandService.updata(id);
        return new DataResult(100,"回显成功",updata);
    }

    @RequestMapping("updatas")
       @ResponseBody
    public DataResult updatas(TbBrand tbBrand){
        Boolean b = brandService.updatas(tbBrand);
        return new DataResult(100,"修改成功");
    }
}
